﻿define(function (require) {
    require('models/Feed');
    var service = require('utility/service');
    require('models/feed');

    window.FeedList = Backbone.Collection.extend({
        model: Feed,
        comparator: function (e) {
            if (e.get('Type') == "notification")
                return -e.get('UpdateOn') * 2; // notification永远排在前面
            else if (e.get('Type') == "update")
                return -e.get('UpdateOn');
            else
                return
        },
        initialize: function () {
            this.getAll();
        },
        getAll: function () {
            var _self = this;
            
            $.mobile.showPageLoadingMsg();
            
            service.GetFeeds(function (feeds) {
                _self.add(feeds);
                _self.trigger("getAll");

                $.mobile.hidePageLoadingMsg();
            });

        },
        unread: function () {
            return this.filter(function (feed) { return !feed.get('IsRead'); });
        }
    });
});
